import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpClientSocket {
	private Socket socket=null;

	public TcpClientSocket(String serverIP,int serverPort) throws IOException {
		socket=new Socket(serverIP,serverPort);
	}
	public void start() {
		Scanner scanner=new Scanner(System.in);
		try(InputStream inputStream=socket.getInputStream();
			OutputStream outputStream=socket.getOutputStream()) {
			PrintWriter printWriter=new PrintWriter(outputStream);
			Scanner scanner1=new Scanner(inputStream);
			while(true) {
				System.out.println("-> ");
				String request=scanner.next();
				printWriter.println(request);
				printWriter.flush();
				String response= scanner1.next();
				System.out.println(response);
			}

		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public static void main(String[] args) throws IOException {
		TcpClientSocket tcpClientSocket=new TcpClientSocket("192.168.58.1",9090);
		tcpClientSocket.start();
	}
}
